package fr.istic.linkedcv.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import fr.istic.linkedcv.client.presentation.impl.UiImpl;
import fr.istic.linkedcv.client.services.PersonneService;
import fr.istic.linkedcv.client.services.PersonneServiceAsync;

public class LinkedCv implements EntryPoint {
	
	private PersonneServiceAsync personneService = GWT.create(PersonneService.class);
	private boolean logged=false;
	private UiImpl uiImpl;
	private PersonneCli personneCli;
	
	public PersonneCli getPersonneCli() {
		return personneCli;
	}
	public void setPersonneCli(PersonneCli personneCli) {		
		this.personneCli = personneCli;
	}
	
	public void initPersonneCli(){
		personneService.myAccount(new AsyncCallback<PersonneCli>() {

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(PersonneCli result) {
				setPersonneCli(result);
				setPresentation();
			}
			
			
		});
	}
	
	public void setPresentation(){
		if(uiImpl==null) uiImpl = new UiImpl(this);
//		uiImpl.init();
	}
	@Override
	public void onModuleLoad() {
		setLogged();
	}
	public void setLogged() {
		personneService.isLogged(new AsyncCallback<Boolean>() {
			
			@Override
			public void onSuccess(Boolean isLogged) {
				logged = isLogged;
				initPersonneCli();
				
				
			}
			
			@Override
			public void onFailure(Throwable caught) {
				
				
			}
		});
	}
	
	public boolean isLogged() {
		return logged;
	}
	public void setLogged(boolean b) {
		logged=b;
		
	}
}
